Skip to content

feat: 增加 sub2api 风格日志与性能统计页面 - #2

Merged
CoderDoubleflower merged 1 commit into
mainfrom
feat/sub2api-ui-observability
Sep 3, 2026
Merged

feat: 增加 sub2api 风格日志与性能统计页面#2
CoderDoubleflower merged 1 commit into
mainfrom
feat/sub2api-ui-observability

Conversation

@CoderDoubleflower

Copy link
Copy Markdown
Owner

变更概览

本次迭代针对嵌入 sub2api 自定义页面和审计链路性能可观测性进行完善:

页面与嵌入

  • 按 sub2api 当前管理端视觉体系重构:青绿色主色、浅灰/深色背景、圆角卡片、页签、统计卡片、表格和状态徽章
  • 增加 运行统计处理日志节点配置 三个页签
  • 支持 ?embedded=1 iframe 嵌入布局
  • 同源时自动监听 sub2api 父页面 <html>.dark;跨域时支持 postMessage 同步主题
  • 向父窗口发送 sub2api-auditer:resize 动态高度事件
  • CSP 明确允许 iframe 嵌入;生产环境可由反向代理进一步限制 frame-ancestors

最近 100 条处理日志

  • 新增固定容量内存环形日志,默认及最大保留最近 100 条
  • 每条请求记录四个关键时间点:
    • 收到 sub2api 请求
    • 开始转发上游 LLM
    • 完整收到上游 LLM 回复
    • 完整回复给 sub2api
  • 记录前处理、上游、响应回写和总耗时
  • 墙钟时间精确到毫秒;耗时使用 perf_counter_ns 单调时钟
  • 记录 Trace ID、双方 Request ID、模型、输入/响应规模、HTTP 状态、审核判定、分类和错误码
  • 不保存完整 Prompt、API Key 或完整模型输出
  • 支持状态/来源过滤、关键词搜索、详情时间线和清空

统计

统计严格从同一份最近 100 条日志实时聚合:

  • 窗口请求量、成功/失败/处理中、最近一分钟 RPM、成功率
  • 平均/P50/P95/最大总耗时
  • 上游平均耗时和 P95
  • 前处理、上游、回写阶段平均耗时
  • Safe / Controversial / Unsafe / 未分类分布
  • 错误码分布、最近 30 条延迟折线、最慢 5 条请求

API 与部署

  • GET /api/logs?limit=100
  • DELETE /api/logs
  • GET /api/statistics
  • 新增 LOG_CAPACITYHTTP_MAX_CONNECTIONSHTTP_MAX_KEEPALIVE 环境变量
  • Docker Compose 已接入对应环境变量
  • 版本升级至 1.1.0
  • README 已补充完整嵌入、日志、统计、性能和安全说明

验证

本地验证结果:

  • PYTHONPATH=src pytest -q:18 passed
  • python -m compileall -q src tests:通过
  • node --check src/sub2api_auditer/static/app.js:通过
  • 静态资源打包读取、HTML 结构和 CSS 括号检查:通过

新增可嵌入的 sub2api 风格统计、日志和配置页;使用最近 100 条内存环形日志记录四个关键时间点与阶段耗时,并提供统计聚合 API、主题同步和完整中文文档。
Copilot AI lite review requested due to automatic review settings September 3, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CoderDoubleflower
CoderDoubleflower merged commit 4579a1e into main Sep 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants